package com.hockeo.client.metadata;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents the metadata for a class that has been tagged using the {@link IMetadataTag}
 * marker interface.
 *
 * @version $Id$
 * @author jjanke
 */
public class Metadata<T extends IMetadataTag>
{
  private final Class<T>                 d_clsType;
  private final List<PropertyDescriptor> d_listProperties = new ArrayList<PropertyDescriptor>();

  /**
   * Creates a new Metadata object.
   *
   * @param cls the class for which to generate metadata
   */
  protected Metadata( Class<T> cls )
  {
    d_clsType = cls;
  }

  /**
   * Adds a new property description to this metadata object.
   *
   * @param strName the name of the property
   * @param clsType the property's type
   * @return the newly added PropertyDescriptor
   */
  protected PropertyDescriptor addProperty( String strName, Class<?> clsType )
  {
    PropertyDescriptor desc = new PropertyDescriptor( strName, clsType );

    d_listProperties.add( desc );

    return desc;
  }

  /**
   * Returns the class that is described by this Metadata object.
   */
  public Class<T> getType()
  {
    return d_clsType;
  }

  /**
   * Returns a list of all properties defined for the class defined by this Metadata
   * object.
   */
  public List<PropertyDescriptor> getProperties()
  {
    return d_listProperties;
  }
}
